package com.test.thread;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2017/7/11
 * Time: 13:46
 * To change this template use Editor | File and Code Templates.
 */
public class Company extends Thread {

    private static boolean isRunning = false;
    private final byte[] lock = new byte[0];

    @Override
    public void run() {
        synchronized (lock) {
            if (isRunning) {
                System.out.println(this.getName() + ",return");
                return;
            } else {
                isRunning = true;
                System.out.println(this.getName() + ",enter");
            }
        }
        System.out.println("service," + this.getName());
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        isRunning = false;
        System.out.println(this.getName() + ",leave");
    }
}
